package computacaografica;

import java.awt.image.BufferedImage;


public class Circunferencia extends Geometrico{

	private int raio;

	public Circunferencia(int raio) {
		this.raio = raio;
	}

	private void circlePoints(int x, int y, int value, BufferedImage imageBuffer) {
		paintPoint(x, y, value, imageBuffer);
		paintPoint(-x, y, value, imageBuffer);
		paintPoint(x, -y, value, imageBuffer);
		paintPoint(-x, -y, value, imageBuffer);
		paintPoint(y, x, value, imageBuffer);
		paintPoint(-y, x, value, imageBuffer);
		paintPoint(y, -x, value, imageBuffer);
		paintPoint(-y, -x, value, imageBuffer);
	}

	private void quadraPoints(int x, int y, int value, BufferedImage imageBuffer){
		paintPoint(x, y, value, imageBuffer);
		paintPoint(-x, y, value, imageBuffer);
		paintPoint(x, -y, value, imageBuffer);
		paintPoint(-x, -y, value, imageBuffer);
	}

	public void drawEqExp(int value, BufferedImage imageBuffer) {
		for (int x = 0; x < raio; x++) {
			double auxY = Math.sqrt(raio * raio - x * x);
			int y = (int) Math.round(auxY);
			quadraPoints(x, y, value, imageBuffer);
		}
	}

	public void drawTrigonomet(int value, BufferedImage imageBuffer){
		double auxX, auxY;
		for (int ang = 0; ang < 180; ang++){
			auxX = raio*Math.cos(ang);
			auxY = raio*Math.sin(ang);

			int x = (int) Math.round(auxX);
			int y = (int) Math.round(auxY);

			circlePoints(x, y, value, imageBuffer);
		}
	}

	public void drawPontoMedio(int value, BufferedImage imageBuffer){
		int x, y;
		float d;
		//valores iniciais
		x = 0;
		y = raio;
		d = 1 - raio;
		circlePoints(x, y, value, imageBuffer);
		while (y > x){
			if (d < 0){
				//Seleciona E
				d = d + 2*x + 3;
			}else{
				//Selecione SE
				d += 2 + 2*(x - y) + 5;
				y--;
			}//end if
			x++;
			circlePoints(x, y, value, imageBuffer);
		}//end while
	}
}
